/*
*VMukti -- An open source video conferencing platform.
*
* Copyright (C) 2007 - 2008, VMukti Solutions Pvt. Ltd.
*
* Hardik Sanghvi <hardik@vmukti.com>
*
* See http://www.vmukti.com for more information about
* the VMukti project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, forums and mailing lists
* for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
using System.Data;
using VMukti.Common;
using VMukti.DataAccess;
using System.Data.SqlClient;
using System.Collections.Generic;
using VMukti.Business.CommonDataContracts;
using VMuktiAPI;

namespace VMukti.Business
{ 
    public class ClsBuddyReqCollection : ClsBaseCollection<ClsBuddyReq>
    {
        public static ClsBuddyReqCollection GetAll()
        {
            
            ClsBuddyReqCollection obj = new ClsBuddyReqCollection();
            if (VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.NodeWithHttp)
            {
                try
                {
                obj.MapObjects(VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("Select * vMyBuddy").dsInfo);
                }
                catch (System.ServiceModel.EndpointNotFoundException e)
                {
                    e.Data.Add("My Key", "GetAll()--:--ClsBuddyReqCollection.cs--:--" + e.Message + " :--:--");
                    ClsException.LogError(e);
                    ClsException.WriteToErrorLogFile(e);
                    VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                    obj.MapObjects(VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("Select * vMyBuddy").dsInfo);
                }
                catch (System.ServiceModel.CommunicationException e)
                {
                    e.Data.Add("My Key", "GetAll()--:--ClsBuddyReqCollection.cs--:--" + e.Message + " :--:--");
                    ClsException.LogError(e);
                    ClsException.WriteToErrorLogFile(e);
                    VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                    obj.MapObjects(VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("Select * vMyBuddy").dsInfo);
                }
            }
            else
            {
                obj.MapObjects(new ClsBuddyReqDataService().BuddyReq_GetAll());
            }
            return obj;
        }

        public static ClsBuddyReqCollection GetByUserID(int UserID)
        {
            ClsBuddyReqCollection obj = new ClsBuddyReqCollection();
            if (VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType == VMuktiAPI.PeerType.NodeWithHttp)
            {                
                List<clsSqlParametersInfo> lstSP = new List<clsSqlParametersInfo>();

                clsSqlParametersInfo objInfo = new clsSqlParametersInfo();
                objInfo.Direction = "Input";
                objInfo.PName = "@pID";
                objInfo.PValue = -1;
                objInfo.PDBType = "BigInt";
                objInfo.PSize = 200;

                clsSqlParametersInfo objInfo2 = new clsSqlParametersInfo();
                objInfo2.Direction = "Input";
                objInfo2.PName = "@pUserID";
                objInfo2.PValue = UserID;
                objInfo2.PDBType = "BigInt";
                objInfo2.PSize = 200;

                lstSP.Add(objInfo);
                lstSP.Add(objInfo2);

                clsSqlParameterContract CSqlInfo = new clsSqlParameterContract();
                CSqlInfo.objParam = lstSP;

                //shilpa code
                //11-Feb-2008
                try
                {
                obj.MapObjects(VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("spGBuddyRequest", CSqlInfo).dsInfo);
                }
                catch (System.ServiceModel.EndpointNotFoundException e)
                {
                    e.Data.Add("My Key", "GetByUserID(int UserID)--:--ClsBuddyReqCollection.cs--:--" + e.Message + " :--:--");
                    ClsException.LogError(e);
                    ClsException.WriteToErrorLogFile(e);
                    VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                    obj.MapObjects(VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("spGBuddyRequest", CSqlInfo).dsInfo);
                }
                catch (System.ServiceModel.CommunicationException e)
                {
                    e.Data.Add("My Key", "GetByUserID(int UserID)--:--ClsBuddyReqCollection.cs--:--" + e.Message + " :--:--");
                    ClsException.LogError(e);
                    ClsException.WriteToErrorLogFile(e);
                    VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                    obj.MapObjects(VMukti.Business.clsDataBaseChannel.chHttpDataBaseService.svcExecuteDataSet("spGBuddyRequest", CSqlInfo).dsInfo);
                }
                //end shilpa code
                //11-Feb-2008

            }
            else
            {
                obj.MapObjects(new VMukti.DataAccess.ClsBuddyReqDataService().BuddyReq_GetByUserID(UserID));
            }
            return obj;
        }
    }
}
